<template>
    <div class="center_div">
        <el-table :data="recordList">
            <el-table-column prop="employeename" label="姓名" min-width="90"></el-table-column>
            <el-table-column prop="departmentname" label="部门" min-width="90"></el-table-column>
            <el-table-column prop="awardname" label="奖品" min-width="90">
                <template slot-scope="scope">
                    <el-tag type="success">{{scope.row.awardname}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="thetime" label="时间" min-width="120"></el-table-column>
            <el-table-column label="状态" min-width="90">
                <template>
                    <el-tag type="warning" effect="plain">未发放</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" min-width="90">
                <template slot-scope="scope">
                    <el-button type="success" @click="GetOutRocard(scope.row.awardrecordid)">发放</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "amuse-grant",
        data() {
            return{
                recordList:  []
            }
        },
        created() {
            this.fetchRocard()
        },
        methods: {
            async fetchRocard(){
                let {code ,data ,msg} = await this.$post('/admin/awardapproval')
                if(code === 200) {
                    this.recordList = data.awardrecord
                }else {
                    this.$message.error(msg)
                }
            },
            async GetOutRocard(rocardID){
                console.log(rocardID)
                let {code ,data ,msg} = await this.$post('/admin/awardrecordupdate',{
                    data: {
                        awardrecordid: rocardID
                    }
                })
                if(code === 200) {
                    let iii = this.recordList.findIndex(item => item.awardrecordid === rocardID)
                    if(iii !== -1)
                        this.recordList.splice(iii,1)
                    this.$message.success("发放奖品成功")
                    console.log(data)
                } else {
                    this.$message.error('发放失败' + msg)
                }
            }
        }
    }
</script>

<style >
    .center_div{
        width: 60%;
        margin:0 auto;
        margin-bottom: 50px;
    }
</style>